package 城堡问题;

import java.util.*;

public class Main {
    static int N = 60, n, m;
    static int[][] g = new int[N][N];
    static boolean[][] st = new boolean[N][N];
    static int[] dx = {0, -1, 0, 1};//能够走的方向
    static int[] dy = {-1, 0, 1, 0};//顺序定义按照他的顺序，西北东南

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                g[i][j] = in.nextInt();
            }
        }
        int cnt = 0, area = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!st[i][j]) {
                    cnt++;
                    area = Math.max(area, bfs(new PII(i, j)));
                }
            }
        }
        System.out.println(cnt);
        System.out.println(area);
    }

    private static int bfs(PII start) {
        int ret = 0;
        Queue<PII> q = new LinkedList<>();
        q.offer(start);
        st[start.x][start.y] = true;
        while (!q.isEmpty()) {
            PII t = q.poll();
            ret++;
            for (int i = 0; i < 4; i++) {
                int x = t.x + dx[i], y = t.y + dy[i];
                if (x < 0 || x >= n || y < 0 || y >= m) {
                    continue;
                }
                if (st[x][y]) {
                    continue;
                }
                if ((g[t.x][t.y] >> i & 1) == 1) {
                    continue;
                }
                st[x][y] = true;
                q.offer(new PII(x, y));
            }
        }
        return ret;
    }
}

class PII {
    int x, y;

    public PII(int x, int y) {
        this.x = x;
        this.y = y;
    }
}